package com.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.user.entity.ResultResponse;
import com.user.mapper.RecordMapper;
import com.user.service.RecordService;
import com.user.vo.RecordVo;
import com.usian.model.record.Recordd;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class RecordServiceImpl extends ServiceImpl<RecordMapper, Recordd> implements RecordService {
    @Autowired
    private RecordMapper recordMapper;

    @Override
    public ResultResponse findUserScore(Integer id) {
        List<Recordd> list = recordMapper.findUserScore(id);
        //排序
        list.sort((o1, o2) -> o2.getDatee().compareTo(o1.getDatee()));
        return ResultResponse.ok().data("score", list);
    }

    @Override
    public RecordVo addRecord(RecordVo recordVo) {
        String name = recordVo.getName();
        Integer score = recordVo.getScore();
        Date datee = recordVo.getDatee();
        Integer uid = recordVo.getUid();
        int result = recordMapper.addRecord(name, score, datee, uid);
        log.info("添加积分记录：" + result);
        return recordVo;
    }


}
